const moment = require('moment');
require('moment/locale/zh-cn');

const monthFormat = 'YYYY-MM';
const DEFAULT_FORMAT = 'YYYYMM';


// 20200122
const result1 = moment('202001220987', 'YYYYMMDD').format('YYYY/MM/DD');
console.log(result1);

const result2 = moment().format(monthFormat);
console.log('%s', result2);

const result3 = moment().diff(moment('202101', monthFormat),'month');
console.log('%s', result3);

const result4 = moment().startOf('month');
console.log('%s', result4);


const result5 = moment().get(monthFormat);
console.log('%s', result5);

const result6 = moment().set({ year: '2020', month: '2' }).format(monthFormat);
console.log('%s', result6);

const result7 = moment('19900101', 'YYYYMM').add('year', 22).format(monthFormat);
console.log(result7);

// 年龄
const isAfterBirthday = (birthday, dest) => {
  const birthdayFormat = birthday ? moment(birthday, DEFAULT_FORMAT) : null;
  const destFormat = dest ? moment(dest, DEFAULT_FORMAT) : null
  return destFormat && birthdayFormat && destFormat > birthdayFormat
}


const result8 = isAfterBirthday('20191028', '20010131');
console.log(result8);

